package cn.xgxd.web;

import cn.xgxd.pojo.Goods;
import cn.xgxd.result.Result;
import cn.xgxd.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    GoodsService goodsService;

    @GetMapping
    public Result findAllpost(@RequestParam(required = false ,defaultValue = "1") Integer page){
        return Result.success(  goodsService.showGoods(page));
    }
    @GetMapping("/allow")
    public Result allowGoods(@RequestParam(required = false ,defaultValue = "1") Integer page){
        return Result.success(  goodsService.allowGoods(page));
    }
    @GetMapping("/{id}")
    public Result selectOneGoods(@PathVariable("id")  String id){
        return Result.success( goodsService.selectOneGoods(id));
    }
    @GetMapping("/count")
    public Result selectGoodsCount(){
        return Result.success(goodsService.selectGoodsCount());
    }

    @PutMapping("/swallow")
    public Result swAllow(@RequestBody Goods goods){
        goodsService.swAllow(goods);
        return Result.success();
    }
    @PostMapping("/add")
    public Result addGoods(@RequestBody Goods goods){
        goodsService.addGoods(goods);
        return Result.success();
    }

    @GetMapping("/basketball")
    public Result selectBasketball(){
        return Result.success(goodsService.basketball());
    }

    @GetMapping("/football")
    public Result selectFootball(){
        return Result.success(goodsService.football());
    }

    @GetMapping("/my")
    public Result selectMy(){
        return Result.success(goodsService.my());
    }

    @GetMapping ("/del/{id}")
    public Result delGoods(@PathVariable("id") String id){
        System.out.println(id);
        goodsService.delGoods(id);
        return Result.success();
    }
}
